<?php


namespace app\api\controller;


use app\common\controller\Api;

class Shop extends Api
{
    protected $noNeedLogin = ['getShopShowData'];
    protected $noNeedRight = ['*'];




    /**
     * 获取店铺系统配置
     *
     * @ApiMethod (GET)
     */
    public function getShopConfig()
    {
        $data = model('app\admin\model\shop\Configsystem')->get(1);
        $this->success('请求成功',$data,200);
    }


    /**
     * 获取入驻申请信息
     *
     * @ApiMethod (GET)
     */
    public function getApplyInfo(\app\common\model\ShopModel $ShopModel)
    {
        $user_id = $this->auth->id;
        $data = $ShopModel->getApplyInfo($user_id);
        $this->success($data['msg'], $data['data'], $data['code']);
    }


    /**
     * 提交店铺入驻信息
     *
     * @ApiMethod (POST)
     * @param string|int $state 店铺类型:0=个人,1=企业,2=旗舰
     * @param string $shopname 店铺名称
     * @param string $name 企业名/姓名
     * @param string $number 统一信用/身份证号
     * @param string $mobile 电话
     * @param string $image 证件图片
     * @param string $wechat 微信号
     * @param string $trademark 商标证书
     * @param string $avatar 店铺头像
     * @param string $bio 店铺简介
     * @param string $content 店铺介绍
     * @param string $city 省市
     * @param string $certificate 转账证明
     */
    public function apply(\app\common\model\ShopModel $ShopModel, \app\api\validate\ShopValidate $ShopValidate)
    {
        $params = $this->request->post();
        if(!$ShopValidate->check($params,[],'apply')){
            $this->success($ShopValidate->getError(),$params,40001);
        }
        $user_id = $this->auth->id;
        $data = $ShopModel->apply($params,$user_id);
        $this->success($data['msg'], $data['data'], $data['code']);
    }


    /**
     * 获取展示页数据
     *
     * @ApiMethod (GET)
     */
    public function getShopShowData(\app\common\model\ShopModel $ShopModel)
    {
        $user_id = $this->auth->id;
        $data = $ShopModel->getShopShowData($user_id);
        $this->success($data['msg'], $data['data'], $data['code']);
    }


    /**
     * 提交店铺展示位入驻信息
     *
     * @ApiMethod (POST)
     * @param int $show_id 展示位ID
     * @param string $certificate 转账证明
     */
    public function applyShopShowLocation(\app\common\model\ShopModel $ShopModel, \app\api\validate\ShopValidate $ShopValidate)
    {
        $params = $this->request->post();
        if(!$ShopValidate->check($params,[],'applyShopShowLocation')){
            $this->success($ShopValidate->getError(),$params,40001);
        }
        $user_id = $this->auth->id;
        $data = $ShopModel->applyShopShowLocation($params,$user_id);
        $this->success($data['msg'], $data['data'], $data['code']);
    }


}